
//ajax  错误返回信息进行提醒
function displayErrors(items) {
    for (var key in items) {
        var obj = $('#' + key);
        var span = '<span style="color:red; margin-left:10px;" class="errs_span">' + items[key] + '</span>';
        $(obj).after(span);
    }
}


//定义ajax提交
function formSubmit(form, callback) {
    var options = {
        url: $(form).attr('action'),
        dataType: 'json',
        iframe: true,
        success: function (result) {
            if (typeof (callback) == 'function') {
                callback(result);
            } else {
                alert('Request error.');
            }
        }
    };
    $(form).ajaxSubmit(options);
    return false;
}

$(document).ready(function () {
    //自定义的ajax效果
    $('.submit_form').click(function () {
        formSubmit(this.form, function (result) {
            $(".errs_span").remove();
			if(result.err){
				displayErrors(result.err);
			}
			if (result.message) {
               alert(result.message);
            }
			if (result.href) {
                location.href = result.href;
            }
        });
    });
    
    //删除操作
    $(".remove_this").click(function(){
        var url = $(this).attr('url');
        if(url && confirm('您确定要执行此操作？')){
            $.post(url,{},function(data){
                if (result.message) {
				   alert(result.message);
				}
                location=location 
            },'json');
        }
    });
    
});




